package com.zhou.core.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Created by zhouyongjun on 2020/7/14
 */
public class GTJdbcConfig {
    private String url;
    private String user;
    private String pwd;

    Map<String,String> extraConfigMaps;
    String driverClassName = "com.mysql.jdbc.Driver";

    public GTJdbcConfig(String user,String pwd,String url,String driverClassName)
    {
        this(user,pwd,url,driverClassName,null);
    }
    public GTJdbcConfig(String user,String pwd,String url,String driverClassName,Map<String,String> extraConfigMaps)
    {
        this.user = user;
        this.pwd = pwd;
        this.url = url;
        this.driverClassName = driverClassName;

        this.extraConfigMaps = extraConfigMaps;
        initExtra();
    }

    private void initExtra() {
        if (extraConfigMaps == null)
        {
            extraConfigMaps = new HashMap<>();
        }
        extraConfigMaps.putIfAbsent(DruidDataSourceFactory.PROP_MAXWAIT,String.valueOf(30 * 1000l));
        extraConfigMaps.putIfAbsent(DruidDataSourceFactory.PROP_TESTWHILEIDLE,String.valueOf(true));
        extraConfigMaps.putIfAbsent(DruidDataSourceFactory.PROP_TESTONBORROW,String.valueOf(true));
        extraConfigMaps.putIfAbsent(DruidDataSourceFactory.PROP_MAXACTIVE,String.valueOf(20));
        extraConfigMaps.putIfAbsent(DruidDataSourceFactory.PROP_INITIALSIZE,String.valueOf(1));
    }

    public Map<String, String> getExtraConfigMaps() {
        return extraConfigMaps;
    }

    public void setExtraConfigMaps(Map<String, String> extraConfigMaps) {
        this.extraConfigMaps = extraConfigMaps;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }


    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }
}
